<?php
if(
	$_GET['open']==1 &&
	strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')!==false &&  // 微信浏览器
	strpos($_SERVER['HTTP_USER_AGENT'], 'Redmi 7') === false    // 不为红米7手机下载pdf文件，自动调起手机自带浏览器
){
	header("Content-Disposition: attachment; filename=\"30006804102.pdf\"");
	header("Content-Type: application/uomg");
}
$iCode = isset($_GET["i_code"]) && $_GET["i_code"] != ""  ? "i_code=" . trim($_GET["i_code"]) : "";
$rCode = isset($_GET["r_code"]) && $_GET["r_code"] != ""  ? "r_code=" . trim($_GET["r_code"]) : "";
?>

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <title>请用系统浏览器打开进行下载</title>
  <link rel="shortcut icon" href="/resource_images/__image_path__/common/logo.png?__static_hash__" />
  <meta http-equiv="Access-Control-Allow-Origin" content="*">
  <link rel="stylesheet" type="text/css" href="css/guide.css?__static_hash__" />
  <script type="text/javascript" src="js/jquery-3.2.1.min.js?__static_hash__"></script>
  <script src="js/clipboard.min.js?__static_hash__"></script>
</head>

<body>
  <div class="weixin_tip">
    <img id="tips" style="width:100%;height:auto;" />
    <div class="copyContainer">
      <button type="button" class="copyUrl">点击复制下载链接</button>
    </div>
  </div>
</body>

</html>
<script>
  $(function () {

    /**
     * Tost提示公共方法
     */
    var Tost = (function () {
      // Tost dom 私有变量
      var tostElem;

      // 创建私有方法生成Tost dmo
      function createElem(text, top, size) {
        // Tost提示样式
        var style = {
          position: "fixed",
          left: "50%",
          top: top + "px",
          fontSize: size + "px",
          background: "rgba(0, 0, 0, 0.9)",
          padding: "8px 20px",
          color: "#ffffff",
          transform: "translateX(-50%)",
          borderRadius: "2px"
        };

        if (tostElem) {
          document.body.removeChild(tostElem);
        }
        tostElem = document.createElement("section");
        tostElem.className = "tost";
        tostElem.innerText = text;
        for (var key in style) {
          tostElem.style[key] = style[key];
        }
        document.body.appendChild(tostElem);
      }

      /**
       * Tost提示构造函数
       * @param {any} option
       */
      function Tost() {
        this.top = 200;
        this.fontSize = 12;
        this.duration = 3000;
      }

      Tost.prototype.init = function (option) {
        var option = option || {};

        this.top = option.top || 200;
        this.fontSize = option.fontSize || 12;
        this.time = null;
      };

      Tost.prototype.info = function (text, duration) {
        clearTimeout(this.time);
        createElem(text, this.top, this.fontSize);

        this.time = setTimeout(function () {
          document.body.removeChild(tostElem);
          tostElem = "";
        }, duration || this.duration);
      };

      return new Tost();
    })();
    var iCode = "<?php echo $iCode;?>";
    var rCode = "<?php echo $rCode;?>";

    var UA = navigator.userAgent;
    if (/MicroMessenger/gi.test(UA) && /android|adr/gi.test(UA)) { //安卓并且为微信
      var url = '?open=1';
      if (iCode) {
        url += '&' + iCode;
      }
      if (rCode) {
        url += '&' + rCode;
      }
      var iframe = document.createElement("iframe");
      iframe.style.display = "none";
      iframe.src = url;
      document.body.appendChild(iframe);
    }

    function isiOS() {
      var u = navigator.userAgent;

      return (
        !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) && u.indexOf('XiaoMi') === -1
      ); //ios终端
    }

    $(".weixin_tip").show();

    if (isiOS()) {
      $("#tips").attr("src", "/resource_images/__image_path__/guide/wxtips_ios.png?__static_hash__");
    } else {
      $("#tips").attr("src", "/resource_images/__image_path__/guide/wxtips_and.png?__static_hash__");
    }

    var clipboard = new ClipboardJS(".copyUrl", {
      text: function (trigger) {
        return location.href;
      }
    });

    clipboard.on("success", function (e) {
      Tost.info("复制成功");
      e.clearSelection(); // 清除选中内容
    });

    clipboard.on("error", function (e) {
      if (isiOS() && browser() === "UC") {
        Tost.info("复制成功");
      } else {
        Tost.info("复制失败");
      }
    });
  });
</script>